package com.kele.service;

import com.rabbitmq.client.Channel;
import freemarker.template.TemplateException;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class PageRabbitListener {

    @Autowired
    PageService pageService;
    @RabbitListener(queues = {"page_queue_1"},concurrency = "1")
    public void recevieMsg(Long goodsId, Message message, Channel channel) throws IOException {

        System.out.println("goodsId" + goodsId);
        System.out.println("执行完业务逻辑");
        try {
            pageService.genHtml(goodsId);
        } catch (TemplateException e) {
            e.printStackTrace();
        }

        long deliveryTag = message.getMessageProperties().getDeliveryTag();
        System.out.println(deliveryTag);

        channel.basicAck(deliveryTag,false);//ACK
    }
}
